package com.mike.layoutdemo415lbx;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class ConstrainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv_title;
    private EditText etId;
    private EditText etPasswd;
    private RadioGroup radioGroup;
    private CheckBox checkBox;
    private RadioButton rbMan;
    private RadioButton rbWoman;
    private Switch aSwitch;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_constraint);
        tv_title = findViewById(R.id.constraintTitle);
        etId = findViewById(R.id.et_name);
        etPasswd = findViewById(R.id.etpasswd);
        radioGroup = findViewById(R.id.radioGroup);
        rbMan = findViewById(R.id.rbman);
        rbWoman = findViewById(R.id.rbWoman);
        button = findViewById(R.id.button);
        checkBox = findViewById(R.id.checkBox);
        aSwitch = findViewById(R.id.switch1);
        button.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        if (TextUtils.isEmpty(etId.getText().toString()) && TextUtils.isEmpty(etPasswd.getText().toString())) {
            Toast.makeText(this, "用户名或密码为空", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!checkBox.isChecked()){
            Toast.makeText(this, "请点击同意按钮", Toast.LENGTH_SHORT).show();
            return;
        }
        String str = etPasswd.getText().toString()+etId.getText().toString()+"\n";
        if(rbMan.isChecked()){
            str+="男";
        }else if(rbWoman.isChecked()){
            str+="女";
        }
        if(aSwitch.isChecked()){
            str+="记住密码已打开"+"\n";
        }
        else if(!aSwitch.isChecked()){
            str+="记住密码已关闭";
        }
        if ( id ==R.id.button) {
            Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        }
    }
}